//
//  ViewController.swift
//  WIFISend
//
//  Created by lete on 2020/7/20.
//  Copyright © 2020 lete. All rights reserved.
//

import UIKit

class ViewController: UIViewController, UIDocumentPickerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        
      let ipAddress = LTHelper.manage.ipAddress
        print(ipAddress)
    }

    @IBAction func 开启WiFi(_ sender: Any) {
        
//       let vc = LTWIFITransportViewController()
       let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "LTWIFITransportViewController")
        self.navigationController?.pushViewController(vc, animated: true)
    }
    
    
    @IBAction func openFiles(_ sender: Any) {
        print("fff")
        let documentPickerController = UIDocumentPickerViewController(documentTypes: ["com.microsoft.powerpoint.​ppt",
        "com.microsoft.word.doc",
        "com.microsoft.excel.xls",
        "com.microsoft.powerpoint.​pptx",
        "com.microsoft.word.docx",
        "com.microsoft.excel.xlsx",
        "public.avi",
        "public.3gpp",
        "public.mpeg-4",
        "com.compuserve.gif",
        "public.jpeg",
        "public.png",
        "public.plain-text",
        "com.adobe.pdf"], in: .import)
        documentPickerController.delegate = self
        present(documentPickerController, animated: true, completion: nil)
    }
    
    func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
        
        if controller.documentPickerMode == UIDocumentPickerMode.import{
            
            for url in urls {
                /// 源文件名字
                let  sourceName = url.lastPathComponent
                /// 源文件路径
                let soureUrlPath =  url.path
                
                let documentBaseUrl = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first
                let targartUrl = documentBaseUrl!.appendingPathComponent(sourceName)
                do {
                    try FileManager.default.moveItem(atPath: soureUrlPath, toPath: targartUrl.path) //FileManager.default.copyItem(at: URL.init(string: soureUrlPath)!, to:ulr!)
                    print("Success to copy file.")
                    
                } catch  {
                    print("Failed to copy file.")
                }
//                NotificationCenter.default.post(name: NSNotification.Name("FileShareNotice"), object: self, userInfo: nil)
                //            }
                
            }
            
            
        }
        
        
    }
    
    
    
}

